package com.xuyuanjia.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.xuyuanjia.web.entity.Subject2;
import com.xuyuanjia.web.service.SubjectService;
@Controller
@RequestMapping(value = "/subject")
public class SubjectController {
	
	@Autowired
	private SubjectService subjectService;
	
	public SubjectController() {}
	
	/**
	 * @throws Exception 
	 * 
	 * @描述:
	 * @方法名: add
	 * @param subject
	 * @return
	 * @返回类型 String
	 * @创建人 Administrator
	 * @创建时间 2016年8月31日上午9:03:03
	 * @修改人 Administrator
	 * @修改时间 2016年8月31日上午9:03:03
	 * @修改备注
	 * @since
	 * @throws
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public String add(Subject2 subject) throws Exception{
		boolean b = subjectService.insert(subject);
		return b + "";
	}
	
	
	@RequestMapping(value = "/getZTreeData", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String getZTreeData() throws Exception{
		return subjectService.getZTreeToSubject();
	}
	
	@RequestMapping(value = "/getOneSubject", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String getOneSubject(Long id) throws Exception{
		Subject2 subject  = subjectService.selectById(id);
		return JSON.toJSONString(subject);
	}
	
	@RequestMapping(value = "/delOneSubject", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String delOneSubject(Long id) throws Exception{
		boolean flag  = subjectService.deleteById(id);
		return JSON.toJSONString(flag);
	}
}